package carcassonne.game.mini.poker;

import carcassonne.game.deck.Deck;
import carcassonne.game.mini.MiniGame;
import carcassonne.game.player.Player;
import io.netty.channel.Channel;
import io.netty.channel.ChannelId;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

public class TexasHoldemPokerGame extends MiniGame {

    public String ID;

    public Deck<Integer> Deck;

    public List<Integer> PublicCards;

    protected Map<Channel, List<Integer>> HandCards;

    public TexasHoldemPokerGame() {
        ID = UUID.randomUUID().toString();

        List<Integer> pokerCards = new ArrayList<>();
        for (int i = 2; i <= 14; i++)
        {
            pokerCards.add(i * 10);
            pokerCards.add(i * 10 + 1);
            pokerCards.add(i * 10 + 2);
            pokerCards.add(i * 10 + 3);
        }
        Deck = new Deck<>("poker", 1, pokerCards);
    }

    protected List<Player> players;

    public void Init(List<Player> players) {
        this.players = players;
        HandCards = new HashMap<>();
        Deck.Shuffle();
    }

    public Map<Channel, List<Integer>> StartGame() {
        Deck.Shuffle();
        PublicCards = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            PublicCards.add(Deck.Next());
        }
        for (Player player : players) {
            List<Integer> hands = new ArrayList<>();
            hands.add(Deck.Next());
            hands.add(Deck.Next());
            HandCards.put(player.channel, hands);
        }
        return HandCards;
    }

    public List<Integer> GetPublicCards(int phase) {
        List<Integer> cards = new ArrayList<>();
        switch (phase) {
            case 1 -> {
                cards.add(PublicCards.get(0));
                cards.add(PublicCards.get(1));
                cards.add(PublicCards.get(2));
            }
            case 2 -> {
                cards.add(PublicCards.get(0));
                cards.add(PublicCards.get(1));
                cards.add(PublicCards.get(2));
                cards.add(PublicCards.get(3));
            }
            case 3 -> {
                cards.add(PublicCards.get(0));
                cards.add(PublicCards.get(1));
                cards.add(PublicCards.get(2));
                cards.add(PublicCards.get(3));
                cards.add(PublicCards.get(4));
            }
        }
        return cards;
    }

    public List<Integer> GetHands(Channel channel) {
        return HandCards.get(channel);
    }
}
